home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / cbibcode.arc / OPEN.C < prev    next >
Encoding:
C/C++ Source or Header  |  1991-08-05  |  719 b   |  24 lines

  1. /* open.c --- p 501 */
  2. #include <stdio.h>
  3. #include <io.h>
  4. #include <fcntl.h>
  5. #include <sys\types.h>
  6. #include <sys\stat.h>
  7. main()
  8. {
  9.     int handle;
  10.     char filename[81];
  11.     printf("Enter name of a file to open: ");
  12.     gets(filename);
  13.                 /* Open the file for write operations.
  14.                  * Don't overwrite existing file. */
  15.     if ((handle = open(filename, O_WRONLY | O_CREAT | O_EXCL,
  16.                         S_IREAD | S_IWRITE))  == -1)
  17.         /* Use perror to print the message so that we also see
  18.          * the error message corresponding to the value of 'errno'*/
  19.         perror("Open failed! ");
  20.     else
  21.         printf("File %s opened successfully\n",filename);
  22.             /* In an actual program we will use the file for I/O.
  23.              * Here we simply exit. */
  24. }